# -*-coding:utf8-*-#
import os
import sys
import time
import json

#
# 计算 帧号时间 
#
def find_frame_pts(in_file, out_file):
    cmd = "ffprobe -select_streams v -show_frames -show_entries frame=best_effort_timestamp_time -of json  %s > %s" % (in_file, out_file)
    os.system(cmd)

#
# 列出 帧号 时间 
#
def list_frame_pts(in_file):
    with open(in_file, encoding='utf-8') as f:
        data = json.load(f)
        frames = data['frames']
        # 分配数组
        total_time = int(float(frames[-1]['best_effort_timestamp_time'])) + 1
        info = [0] * total_time

        # 统计
        for frame in frames:
            frame_time = int(float(frame['best_effort_timestamp_time']))
            info[frame_time] += 1

        # 显示
        for index, pts in enumerate(info):
            print("time = %s  frames = %s" % (index, pts))


#
# 统计 每秒的帧数 
#
def get_frames_per_second(in_file):
    return "am start {}".format(app)

def main():
    in_file = "/Users/wenqiang/temp/跟不准与跟的准/杜震宇_2021西甲巴塞VS皇马（集锦）-iphone跟不准问题.mov"
    #in_file = "/Users/wenqiang/temp/跟不准与跟的准/888_1568pi_18sec_VFR_voice_10m_15681569sar_296523dar_null.mov"
    out_file = "/Users/wenqiang/temp/跟不准与跟的准/1.json"
    find_frame_pts(in_file, out_file)
    list_frame_pts(out_file)

if __name__ == '__main__':
    main()
